﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.Contracts;
using PhysicsEngine.Collision;
using PhysicsEngine.Collision.Shapes;
using PhysicsEngine.Common;

namespace PhysicsEngine.Dynamics
{
  public class World
  {
    public IList<IBody> Bodies { get; private set; }

    public World()
    {
      Bodies = new List<IBody>();
    }

    [ContractInvariantMethod]
    private void ObjectInvariant()
    {
      Contract.Invariant(Contract.ForAll<IBody>(Bodies, item => item != null));
    }


    public void Update(float dt)
    {
    }

    public IBody CreateBody(IShape shape, Vector2 position, Material material)
    {
      Contract.Ensures(Bodies.Count == Contract.OldValue<int>(Bodies.Count) + 1);

      Body body = new Body(shape, position, material);
      Bodies.Add(body);
      return body;
    }
  }
}
